package com.saver.view.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ToggleButton;

import com.saver.R;
import com.saver.core.domain.Categoria;
import com.saver.view.TransactionListActivity;

import java.util.List;

/**
 * Created by HGonzales.
 */
public class CategoriaFilterAdapter extends BaseAdapter {

    private static LayoutInflater inflater = null;

    private List<Categoria> data;

    public CategoriaFilterAdapter(Activity activity, List<Categoria> data) {
        this.data = data;
        this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.categoria_filter, null);
        }
        Categoria categoria = data.get(position);
//        ToggleButton button = (ToggleButton) convertView.findViewById(R.id.category_button);
        CheckBox button = (CheckBox) convertView.findViewById(R.id.category_button);
//        button.setTextOff(categoria.getNombre());
//        button.setTextOn(categoria.getNombre());
        button.setText(categoria.getNombre());
        button.setChecked(true);
        String[] rgb = categoria.getColor().split(",");
        int color = Color.rgb(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
        button.setBackgroundColor(color);
        button.setTextColor(Color.WHITE);
        return convertView;
    }
}
